package com.owen.l3;

import java.util.ArrayList;
import java.util.List;

public class MySolution1 {
    public int lengthOfLongestSubstring(String s) {
        int length=s.length();

        List<Character> history=new ArrayList<>(length);

        int result=0,max=0;
        for (int i = 0; i < length; i++) {
            Character character = s.charAt(i);
            int index = history.indexOf(character);
            if(index==-1){
                history.add(character);
                result++;
                result=Math.max(max,history.size());
                max=result;
            }else{
                result=Math.max(max,history.size());
                max=result;
                history = history.subList(index+1, history.size());
                history.add(character);
                result=result-index;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        int abcabcbb = new MySolution1().lengthOfLongestSubstring("nfpdmpi");
        System.out.println(abcabcbb);
    }
}
